<?php
require_once('global.php');

if (isset($_GET['action']) && $_GET['action'] == 'out')
{
	Cookie('login', '0');
	showAlert("您已经退出登录","index.php");
}
else
{
	if (empty($_POST['loginname']) || empty($_POST['loginpwd'])) 
	{
		exit('empty');
	}
	else 
	{
		//empty($_POST['ck']) && exit('nock');
		//$ck = strtolower($_POST['ck']);
		//GdConfirm($ck);
		$username = trim($_POST['loginname']);
		$password = md5(trim($_POST['loginpwd']));
		$rs = $db->get_one("SELECT * FROM cms_user WHERE username='$username' AND password='$password'");
		if (!empty($rs))
		{

			if ($_POST['autologin']) {
				$time = 'F';
				Cookie('login', $username . "\t" . $password, $time);
			} else {
				Cookie('login', $username . "\t" . $password);
			}
			exit('OK');
		}
		else
		{
			exit('用户名密码错误！');
		}
	}
}
?>